package com.tmc.entity.inthotel;

import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * ToActivity entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see entity.ToActivity
 * @author MyEclipse Persistence Tools
 */

public class ToActivityDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(ToActivityDAO.class);
	// property constants
	public static final String ACTIVITY_NAME = "activityName";
	public static final String DESTINATION_ID = "destinationId";
	public static final String ACTIVITY_LATITUDE = "activityLatitude";
	public static final String ACTIVITY_LONGITUDE = "activityLongitude";
	public static final String ADDRESS = "address";
	public static final String ZIP = "zip";
	public static final String CITY = "city";
	public static final String COUNTRY_CODE = "countryCode";
	public static final String DESTINATION_CODE = "destinationCode";
	public static final String STARS = "stars";
	public static final String STATUS = "status";
	public static final String ACTIVITY_CATEGORY_ID = "activityCategoryId";
	public static final String ACTIVITY_CATEGORY = "activityCategory";
	public static final String PROVIDER_ID = "providerId";
	public static final String BEST_VAL = "bestVal";

	public void save(ToActivity transientInstance) {
		log.debug("saving ToActivity instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(ToActivity persistentInstance) {
		log.debug("deleting ToActivity instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ToActivity findById(java.lang.Integer id) {
		log.debug("getting ToActivity instance with id: " + id);
		try {
			ToActivity instance = (ToActivity) getSession().get(
					"entity.ToActivity", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(ToActivity instance) {
		log.debug("finding ToActivity instance by example");
		try {
			List results = getSession().createCriteria("entity.ToActivity")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ToActivity instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from ToActivity as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByActivityName(Object activityName) {
		return findByProperty(ACTIVITY_NAME, activityName);
	}

	public List findByDestinationId(Object destinationId) {
		return findByProperty(DESTINATION_ID, destinationId);
	}

	public List findByActivityLatitude(Object activityLatitude) {
		return findByProperty(ACTIVITY_LATITUDE, activityLatitude);
	}

	public List findByActivityLongitude(Object activityLongitude) {
		return findByProperty(ACTIVITY_LONGITUDE, activityLongitude);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByZip(Object zip) {
		return findByProperty(ZIP, zip);
	}

	public List findByCity(Object city) {
		return findByProperty(CITY, city);
	}

	public List findByCountryCode(Object countryCode) {
		return findByProperty(COUNTRY_CODE, countryCode);
	}

	public List findByDestinationCode(Object destinationCode) {
		return findByProperty(DESTINATION_CODE, destinationCode);
	}

	public List findByStars(Object stars) {
		return findByProperty(STARS, stars);
	}

	public List findByStatus(Object status) {
		return findByProperty(STATUS, status);
	}

	public List findByActivityCategoryId(Object activityCategoryId) {
		return findByProperty(ACTIVITY_CATEGORY_ID, activityCategoryId);
	}

	public List findByActivityCategory(Object activityCategory) {
		return findByProperty(ACTIVITY_CATEGORY, activityCategory);
	}

	public List findByProviderId(Object providerId) {
		return findByProperty(PROVIDER_ID, providerId);
	}

	public List findByBestVal(Object bestVal) {
		return findByProperty(BEST_VAL, bestVal);
	}

	public List findAll() {
		log.debug("finding all ToActivity instances");
		try {
			String queryString = "from ToActivity";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ToActivity merge(ToActivity detachedInstance) {
		log.debug("merging ToActivity instance");
		try {
			ToActivity result = (ToActivity) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ToActivity instance) {
		log.debug("attaching dirty ToActivity instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ToActivity instance) {
		log.debug("attaching clean ToActivity instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}